import { createStore } from 'vuex'
import router, { dynamicRoutes} from '@/router'
import { RouteRecordRaw } from 'vue-router'
export default createStore({
  state: {
    routes: []
  },
  mutations: {
    SET_ROUTES(state, routes) {
      state.routes = routes

      console.log(routes);
      
      routes.forEach((v: RouteRecordRaw) => {
        router.addRoute('layout', v)
      })
    }
  },
  actions: {
    setRoutes({ commit }, roles) {
      const routes = dynamicRoutes.filter(v => {
        return roles.includes(v.meta!.role)
      })
      commit('SET_ROUTES', routes)
    }
  },
  modules: {
  }
})
